package com.sanjiahantang.ythshopping.activity.me;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanjiahantang.ythshopping.R;
import com.sanjiahantang.ythshopping.activity.BaseActivity;
import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.ShareSqMsgModel;
import com.sanjiahantang.ythshopping.model.UserInforModel;
import com.sanjiahantang.ythshopping.presenter.ShareSQMsgPresenter;
import com.sanjiahantang.ythshopping.umeng.share.Share;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.ShareSqView;
import com.squareup.okhttp.Request;

import java.util.Map;

/**
 * Created by admin on 2017/7/30.
 */

public class ShareSqcodeActivity extends BaseActivity implements ShareSqView{

    WebView wv_page;
    Button btn_share;
    ShareSqMsgModel model;

    TextView tv_title;
    ImageView iv_back;
    ShareSQMsgPresenter msgPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public void initView() {
        super.initView();
        setContentView(R.layout.activity_share_sq);


        msgPresenter = new ShareSQMsgPresenter(this,this);
       wv_page= (WebView) findViewById(R.id.wv_share_page);
        btn_share= (Button) findViewById(R.id.btn_sharesq_share);
        tv_title= (TextView) findViewById(R.id.title);
        iv_back= (ImageView) findViewById(R.id.back);

        WebSettings webSettings = wv_page.getSettings();
        wv_page.setWebViewClient(new WebViewClient());
        wv_page.setWebChromeClient(new WebChromeClient());
        //设置WebView属性，能够执行Javascript脚本
        webSettings.setJavaScriptEnabled(true);
        // 设置允许JS弹窗
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        //wv_page.loadUrl(ConfigValue.MAIN_URL+"compound_index.php?act=qrcode&&key="+ConfigValue.DATA_KEY);
        //http://www.yuetianhe.com/mobile/goods.php?id=428





        msgPresenter.LoadShareMsg();
    }





    @Override
    public void getShareMsg(final ShareSqMsgModel model) {
        if (model.getCode().equals("1"))
        {
            this.model=model;

//            final String shareUrl = ConfigValue.MAIN_URL+"compound_index.php?act=qrcode&uid=" + ConfigValue.uInfor.getUser_id();
            final String shareUrl = model.getData().getLink();
            wv_page.loadUrl(shareUrl);
            tv_title.setText("分享二维码");
            iv_back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });
            btn_share.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //new Share(ShareSqcodeActivity.this,model.getData().title, model.getData().getDesc(),ConfigValue.APP_ID+"compound_index.php?act=qrcode&&key="+ConfigValue.DATA_KEY,model.getData().getImgUrl());
                    new Share(ShareSqcodeActivity.this,"分享", model.getData().getDesc(),shareUrl,model.getData().getImgUrl());
                }
            });
        }
    }


}
